#coding:utf-8

"""
cookie属性:
	cookie名字(name)
	cookie值(value)
	cookie过期时间(Expires/Max-Age)
	cookie作用路径(Path)
	cookie所在域名(Domain)
	使用cookie进行安全连接(Secure)
注: 前两个参数是cookie应用的必要条件,此外还包括cookie大小等. cookie保存在客户端,但是其过期时间保存在服务端
在爬虫时,有些可能需要登录,cookie保存用户信息,以简化登录或验证过程,不然就必须使用cookie处理器来实现登录过程从而记录登录的cookie信息,然后再发送爬取请求,详见renren.login.py

"""

import urllib2


def send_request():

    headers = {
        "Accept" : "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
        #"Accept-Encoding" : "gzip, deflate",
        "Accept-Language" : "zh-CN,zh;q=0.9,en;q=0.8",
        "Cache-Control" : "max-age=0",
        "Connection" : "keep-alive",
        #保存登录的cookie信息
	    "cookie": "anonymid=johyh9c1g2zvhh; depovince=GW; jebecookies=62053385-98b5-4fd1-88e5-7707ba47fe34|||||; _r01_=1; ick_login=21ee2ce2-ecd4-461f-9747-cc0c836c0b9f; _de=BF09EE3A28DED52E6B65F6A4705D973F1383380866D39FF5; p=5b5906d73f4e66f13265ab201592d0e59; first_login_flag=1; ln_uact=mr_mao_hacker@163.com; ln_hurl=http://hdn.xnimg.cn/photos/hdn321/20180921/1130/main_Affp_c9750000af421986.jpg; t=83eb82826c308a8c651018979afe86d99; societyguester=83eb82826c308a8c651018979afe86d99; id=327550029; xnsid=eadf10a5; loginfrom=syshome; ch_id=10016; JSESSIONID=abcaO5hpeFBh7bzfpivCw; jebe_key=2f4bdb41-e638-4ca9-a40e-8200758fa1ae%7Cc13c37f53bca9e1e7132d4b58ce00fa3%7C1542247744509%7C1%7C1542247746950; wp_fold=0",
	    "Host" : "www.renren.com",
        "Referer" : "http://zhibo.renren.com/top",
        "Upgrade-Insecure-Requests" : "1",
        "User-Agent" : "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36"
        }

    url_list = [
            "http://www.renren.com/327550029/profile",
            "http://www.renren.com/410043129/profile"
            ]

    for index, url in enumerate(url_list):
        request = urllib2.Request(url, headers=headers)
        response = urllib2.urlopen(request)

        with open(str(index) + ".html", "w") as f:
            f.write(response.read())


if __name__ == "__main__":
    send_request()

